package com.app.manager;

import com.app.bean.UserDetail;
import com.app.dao.UserDAO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by IntelliJ IDEA.
 * User: Murilo
 * Date: 07/12/11
 * Time: 21:43
 * To change this template use File | Settings | File Templates.
 */
public class UserManager {

    private static Logger logger = Logger.getLogger(UserManager.class);

    private UserDAO userDAO;

    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }

    public String saveNewUser(String userName, String userEmail, String userPass, String userRole){
        String result = "";
        UserDetail bean = new UserDetail();
        bean.setUserName(userName);
        bean.setUserEmail(userEmail);
        bean.setUserPassword(userPass);
        bean.setUserRole(userRole);
        try{
            userDAO.saveUser(bean);
            result = "User saved: " + bean.getUserName();
        } catch (Exception ex){
            logger.error("Error to save a new user", ex);
            result = "Error to save user: " + bean.getUserName();
        }
        return result;
    }

}